package com.sunshine.androidjavapractise.mvp.model;

import android.os.Handler;
import android.os.Message;

import com.sunshine.androidjavapractise.mvp.MessageInfo;
import com.sunshine.androidjavapractise.mvp.interfaces.IDownloadModel;
import com.sunshine.androidjavapractise.mvp.interfaces.IDownloadPresenter;

public class DownloadModel implements IDownloadModel {
    private IDownloadPresenter mDownloadPresenter;
    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case MessageInfo.MSG_PROGRESS: {
                    int progress = msg.arg1;
                    if (progress < MessageInfo.MAX_PERCENT) {
                        mDownloadPresenter.progress(progress);
                    } else {
                        mDownloadPresenter.success("1");
                    }
                    break;
                }
                case MessageInfo.MSG_ERROR: {
                    mDownloadPresenter.fail();
                }

            }
        }
    };

    public DownloadModel(IDownloadPresenter downloadPresenter) {
        mDownloadPresenter = downloadPresenter;
    }

    @Override
    public void download(String url) {

    }
}
